<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<style>
    .layui-form input[type=radio]{
        display: inline-block !important;
    }
    .layui-form input[type=checkbox]{
        display: inline-block !important;
    }

    .layui-form-label {
        float: left;
        display: block;
        padding: 9px 15px;
        width: 100px !important;
        font-weight: 400;
        line-height: 20px;
        text-align: right;
    }
</style>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend></legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">执行器</label>
                            <div class="layui-input-inline">
                                <select name="jobActuator" lay-verify="required">
                                    <option th:each="dict,iterStat : ${jobActuatorList}" th:text="${dict.title}"
                                            th:value="${dict.id}" th:selected="${iterStat.index ==0}"></option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <select name="triggerStatus" lay-verify="required">
                                    <option value="-1" selected>全部</option>
                                    <option value="0">停止</option>
                                    <option value="1">运行</option>
                                </select>
                            </div>

                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" name="jobDesc" autocomplete="off" placeholder="请输入任务描述" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" name="title" autocomplete="off" placeholder="请输入JobHandler" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" name="author" autocomplete="off" placeholder="请输入负责人" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <button data-modal-action="open" data-modal-target="myModal"   class="layui-btn layui-btn-normal" >添加</button>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>


        <script type="text/html" id="test-dropdown-toolbar-barDemo">
            <a class="layui-btn layui-btn-xs" lay-event="more">操作 <i class="layui-icon layui-icon-down"></i></a>
        </script>


    </div>
</div>


<div id="myModal" class="modal">
    <div class="modal-content modal-normal">
        <span class="close">&times;</span>

        <div class="layui-form layuimini-form">
            <p style="margin: 0 0 5px 20px;text-align: left;border-bottom: 1px solid #e5e5e5;color: gray;">基础配置</p>

            <div class="layui-form-item" style="text-align: center;margin-bottom: 8px">
                <div class="layui-inline" style="width: 40%">
                    <label class="layui-form-label"><span style="font-weight: bold">执行器</span><span style="color: red">*</span></label>
                    <div class="layui-input-block">

                        <select id="jobActuator" name="jobActuator" lay-verify="required">
                            <option th:each="dict,iterStat : ${jobActuatorList}" th:text="${dict.title}"
                                    th:value="${dict.id}" th:selected="${iterStat.index ==0}"></option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline" style="width: 40%">
                    <input id="id" style="display: none">
                    <label class="layui-form-label"><span style="font-weight: bold">任务描述</span><span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" id="jobDesc" name="jobDesc" placeholder="请输入任务描述"  class="layui-input">
                    </div>
                </div>

            </div>

            <div class="layui-form-item" style="text-align: center;margin-bottom: 8px">
                <div class="layui-inline" style="width: 40%">
                    <label class="layui-form-label"><span style="font-weight: bold">负责人</span><span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="author" id="author" placeholder="请输入负责人"  class="layui-input">
                    </div>

                </div>

                <div class="layui-inline"  style="width: 40%">
                    <label class="layui-form-label"><span style="font-weight: bold">报警邮件</span><span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" id="alarmEmail" name="alarmEmail" placeholder="请输入报警邮件列表，多个以逗号分隔"  class="layui-input">
                    </div>

                </div>
            </div>

            <p style="margin: 0 0 5px 20px;text-align: left;border-bottom: 1px solid #e5e5e5;color: gray;">调度配置</p>


            <div class="layui-form-item" style="text-align: center;margin-bottom: 8px">
                <div class="layui-inline" style="width: 40%">
                    <label class="layui-form-label"><span style="font-weight: bold">调度类型</span><span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <select name="scheduleType" id="scheduleType" lay-verify="required" lay-filter="selectScheduleType" >
                            <option th:each="dict,iterStat : ${ScheduleTypeEnum}" th:text="${dict.title}"
                                    th:value="${dict}" th:selected="${iterStat.index ==1}"></option>
                        </select>
                    </div>

                </div>

                <div class="layui-inline"  style="width: 40%;visibility: visible" >
                    <div style="display: block" id="id_cron">
                        <label class="layui-form-label"><span style="font-weight: bold">Cron</span><span style="color: red">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" id="schedule_conf_cron" >
                        </div>
                    </div>
                    <div style="display: none" id="id_none">
                        <label class="layui-form-label"><span style="font-weight: bold"></span><span style="color: red"></span></label>
                        <div class="layui-input-block">

                        </div>
                    </div>
                    <div style="display: none" id="id_fix_rate">
                        <label class="layui-form-label"><span style="font-weight: bold">固定速率</span><span style="color: red">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" id="schedule_conf_fix_rate" class="layui-input">
                        </div>
                    </div>
                </div>

            </div>

            <p style="margin: 0 0 5px 20px;text-align: left;border-bottom: 1px solid #e5e5e5;color: gray;">任务配置</p>


            <div class="layui-form-item" style="text-align: center;margin-bottom: 8px">
                <div class="layui-inline" style="width: 40%">
                    <label class="layui-form-label"><span style="font-weight: bold">运行模式</span><span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <select name="glueType" id="glueType" lay-verify="required" lay-filter="selectGlueType" >
                            <option th:each="dict,iterStat : ${GlueTypeEnum}" th:text="${dict.desc}"
                                    th:value="${dict}" th:selected="${iterStat.index ==0}"></option>
                        </select>
                    </div>

                </div>

                <div class="layui-inline"  style="width: 40%">
                    <label class="layui-form-label"><span style="font-weight: bold">JobHandler</span><span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" id="executorHandler" name="executorHandler" placeholder="请输入JobHandler"  class="layui-input">
                    </div>

                </div>
            </div>


            <div class="layui-form-item" style="text-align: center;width: 80%;margin-bottom: 8px;margin-left: 30px">
                <label class="layui-form-label"><span style="font-weight: bold">任务参数</span><span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <textarea  style="min-height: 50px" id="executorParam" name="executorParam" placeholder="请输入任务参数"  class="layui-textarea"></textarea>
                </div>
            </div>
            <p style="margin: 0 0 5px 20px;text-align: left;border-bottom: 1px solid #e5e5e5;color: gray;">高级配置</p>

            <div class="layui-form-item" style="text-align: center;margin-bottom: 8px">
                <div class="layui-inline" style="width: 40%">
                    <label class="layui-form-label"><span style="font-weight: bold">路由策略</span><span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <select name="executorRouteStrategy" id="executorRouteStrategy" lay-verify="required" lay-filter="selectExecutorRouteStrategy" >
                            <option th:each="dict,iterStat : ${ExecutorRouteStrategyEnum}" th:text="${dict.title}"
                                    th:value="${dict}" th:selected="${iterStat.index ==0}"></option>
                        </select>
                    </div>

                </div>

                <div class="layui-inline"  style="width: 40%">
                    <label class="layui-form-label"><span style="font-weight: bold">子任务ID</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="childJobid" id="childJobid" placeholder="请输入子任务ID，多个逗号分隔"  class="layui-input">
                    </div>

                </div>
            </div>
            <div class="layui-form-item" style="text-align: center;margin-bottom: 8px">
                <div class="layui-inline" style="width: 40%">
                    <label class="layui-form-label"><span style="font-weight: bold">调度过期策略</span><span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <select name="misfireStrategy" id="misfireStrategy" lay-verify="required" lay-filter="selectMisfireStrategy" onchange="selectMisfireStrategy(data)">
                            <option th:each="dict,iterStat : ${MisfireStrategyEnum}" th:text="${dict.title}"
                                    th:value="${dict}" th:selected="${iterStat.index ==0}"></option>
                        </select>

                    </div>

                </div>

                <div class="layui-inline"  style="width: 40%">
                    <label class="layui-form-label"><span style="font-weight: bold">阻塞处理策略</span><span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <select name="executorBlockStrategy" id="executorBlockStrategy" lay-verify="required" lay-filter="selectExecutorBlockStrategy" onchange="selectExecutorBlockStrategy(data)">
                            <option th:each="dict,iterStat : ${ExecutorBlockStrategyEnum}" th:text="${dict.title}"
                                    th:value="${dict}" th:selected="${iterStat.index ==0}"></option>
                        </select>
                    </div>

                </div>
            </div>
            <div class="layui-form-item" style="text-align: center;margin-bottom: 8px">
                <div class="layui-inline" style="width: 40%">
                    <label class="layui-form-label"><span style="font-weight: bold">任务超时时间</span><span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="executorTimeout" id="executorTimeout" placeholder="请输入任务超时时间"  class="layui-input">
                    </div>

                </div>

                <div class="layui-inline"  style="width: 40%">
                    <label class="layui-form-label"><span style="font-weight: bold">失败重试次数</span><span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="executorFailRetryCount" id="executorFailRetryCount" placeholder="请输入失败重试次数"  class="layui-input">
                    </div>

                </div>
            </div>






            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" onclick="saveJobInfo()" >保  存</button>
                    <button class="layui-btn layui-btn-primary" onclick="cancelBtn()">取  消</button>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="runOnceTimeId" class="modal">
    <div class="modal-content" style="width: 600px">
        <span class="close" >&times;</span>
        <div class="layui-form layuimini-form">
            <p style="margin: 10px 0 5px 20px;text-align: left;border-bottom: 1px solid #e5e5e5;color: gray;">执行一次</p>
            <div class="layui-form-item" style="text-align: center;width: 80%;margin-bottom: 8px;margin-left: 30px">
                <label class="layui-form-label"><span style="font-weight: bold">任务参数</span><span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <textarea  style="min-height: 50px" id="executorParamOnTime" name="executorParam" placeholder="请输入任务参数"  class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item" style="text-align: center;width: 80%;margin-bottom: 8px;margin-left: 30px">
                <label class="layui-form-label"><span style="font-weight: bold">机器地址</span><span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <textarea  style="min-height: 50px" id="addressListOnceTime" name="addressListOnceTime" placeholder="请输入机器地址"  class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" onclick="exeOnceTime()" >保  存</button>
                    <button class="layui-btn layui-btn-primary" onclick="cancelOnceTime()">取  消</button>
                </div>
            </div>
    </div>
    </div>
</div>
<link href="/plugins/cronGen/bootstrap.min.css" rel="stylesheet">
<link href="/plugins/cronGen/cronGen.css" rel="stylesheet">
<link href="/plugins/cronGen/font/font-awesome.min.css" rel="stylesheet">
<script src="/plugins/cronGen/jquery-2.1.4.min.js"></script>
<script src="/plugins/cronGen/bootstrap.min.js"></script>
<script src="/plugins/cronGen/cronGen.min.js" charset="utf-8"></script>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    var jobId = undefined;
    var table = undefined;
    layui.use(['form', 'table', 'dropdown'], function () {
        var $ = layui.jquery,
            form = layui.form,
            dropdown = layui.dropdown,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/job_info/pageList',
            method: 'post',
            // toolbar: '#toolbarDemo',
            where:{jobActuator:$("select[name='jobActuator']").val(),triggerStatus:$("select[name='triggerStatus']").val()},
            parseData: function (res) {
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.recordsTotal, //解析数据长度
                    "data": res.data //解析数据列表
                };
            },
            cols: [
                [
                {field: 'id',title: '任务ID'},
                {field: 'jobDesc', title: '任务描述'},
                {
                        field: 'scheduleType',event:'scheduleType', title: '调度类型',
                        templet: function ( d) {
                            if (d.scheduleConf) {
                                return d.scheduleType + '：'+ d.scheduleConf;
                            } else {
                                return d.scheduleType;
                            }
                        }
                },
                {field: 'glueType', title: '运行模式',
                   templet: function (d) {
                        var glueTypeTitle = findGlueTypeTitle(d.glueType);
                        if (d.executorHandler) {
                            return glueTypeTitle +"：" + d.executorHandler;
                        } else {
                            return glueTypeTitle;
                        }
                    }
                 },

                    {field: 'author', title: '责任人'},
                    {field: 'triggerStatus', title: '状态',
                        templet: function (d) {
                            // status
                            if (1 == d.triggerStatus) {
                                return '<small class="label label-success" >RUNNING</small>';
                            } else {
                                return '<small class="label label-default" >STOP</small>';
                            }
                            return d.triggerStatus;
                        }
                    },
                {title: '操作', minWidth: 90, toolbar: '#test-dropdown-toolbar-barDemo', align: "center"}
             ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            pageSize: 15,
            page: true,
             request: {
                pageName: 'page',
                limitName: 'rows'
            } ,
            skin: 'line'
        });
        form.on('select(selectScheduleType)', function (data) {
            console.log(data); //得到select原始DOM对象
            if (data.value=='NONE') {
                document.getElementById('id_none').style.display="block";
                document.getElementById('id_cron').style.display="none";
                document.getElementById('id_fix_rate').style.display="none";
            }else if (data.value=='CRON') {
                document.getElementById('id_none').style.display="none";
                document.getElementById('id_cron').style.display="block";
                document.getElementById('id_fix_rate').style.display="none";
            }else if (data.value=='FIX_RATE') {
                document.getElementById('id_none').style.display="none";
                document.getElementById('id_cron').style.display="none";
                document.getElementById('id_fix_rate').style.display="block";
            }
            
        });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: data.field
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '新增执行器',
                    type: 2,
                    shade: 0,
                    maxmin:true,
                    shadeClose: false,
                    area: ['80%', '100%'],
                    content: '/job_info/add',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            var that = this;
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['60%', '80%'],
                    content: '/job_actuator/add?id='+data.id,
                    yes:function () {
                        console.log(1111123);
                    }
                },
                function  cancel(){
                    //右上角关闭回调
                    console.log(123455666);
                }
              );
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });
            }else if (obj.event === 'more') {
                //更多下拉菜单

                var czList = [{
                    title: '编辑'
                    ,id: 'editJob'
                },{
                    title: '删除'
                    ,id: 'deleteJob'
                },{
                    title: '执行一次'
                    ,id: 'oneTime'
                }, {
                    title: '查询日志'
                    ,id: 'queryLog'
                }, {
                    title: '注册节点'
                    ,id: 'registerAddress'
                }
                    , {
                        title: '启动'
                        ,id: 'start'
                    }, {
                        title: '停止'
                        ,id: 'stop'
                    }
                ];
                if (data.scheduleType == 'CRON' || data.scheduleType == 'FIX_RATE') {
                  czList.push({
                      title: '下次执行时间'
                      ,id: 'nextTime'
                  });
                }

                dropdown.render({
                    elem: that
                    ,show: true //外部事件触发即显示
                    ,data: czList
                    ,click: function(res, othis){
                        //根据 id 做出不同操作
                        if(res.id === 'editJob'){
                            console.log('-------othisothisothis-------------',othis);
                            console.log('-------datadatadatadata-------------',data);
                            var targetModal = document.getElementById('myModal');
                            openModalEdit(targetModal,data,form);
                        }else if(res.id === 'oneTime'){
                            console.log('-------othisothisothis-------------',othis);
                            console.log('-------datadatadatadata-------------',data);
                            var targetModal = document.getElementById('runOnceTimeId');
                            openModal2(targetModal,data.id);
                        }

                        else if(res.id === 'queryLog'){
                            var logHref = '/log_info?jobId='+ data.id;
                            window.location.href=logHref;
                        }
                        else if (res.id === 'deleteJob'){
                            layer.confirm( '确认删除？' , {
                                icon: 3,
                                title: '系统提示' ,
                                btn: [ '确定', '取消' ]
                            }, function(index){
                                layer.close(index);
                                $.ajax({
                                    url: '/job_info/delete',
                                    type: 'POST',
                                    data : {
                                        "id" : data.id
                                    },
                                    dataType : "json",
                                    success: function (res) {
                                        console.log('----------back------ddddddd',res)
                                        if (res.code == "200") {
                                            layer.alert('删除成功', {
                                                time: 1*1000
                                                ,success: function(layero, index){
                                                    var timeNum = this.time/1000, setText = function(start){
                                                        layer.title((start ? timeNum : --timeNum) + ' 秒后关闭', index);
                                                    };
                                                    setText(!0);
                                                    this.timer = setInterval(setText, 1000);
                                                    if(timeNum <= 0) clearInterval(this.timer);
                                                    table.reload('currentTableId', {
                                                        page: {
                                                            curr: 1
                                                        }
                                                        , where: data.field
                                                    }, 'data');
                                                }
                                                ,end: function(){
                                                    clearInterval(this.timer);
                                                    layer.close(index);
                                                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                                                    parent.layer.close(iframeIndex);
                                                    window.parent.reload();
                                                }
                                            });
                                        } else {
                                            layer.open({
                                                title: res.message,
                                                btn: [ '确认' ],
                                                content: (res.message || '退出失败' ),
                                                icon: '2'
                                            });
                                        }

                                    },
                                    error: function (error) {

                                    }
                                })

                            });
                        }
                        else if (res.id === 'start'){
                            layer.confirm( '确认启动？' , {
                                icon: 3,
                                title: '系统提示' ,
                                btn: [ '确定', '取消' ]
                            }, function(index){
                                layer.close(index);
                                $.ajax({
                                    url: '/job_info/start',
                                    type: 'POST',
                                    data : {
                                        "id" : data.id
                                    },
                                    dataType : "json",
                                    success: function (res) {
                                        console.log('----------back------ddddddd',res)
                                        if (res.code == "200") {
                                            layer.alert('启动成功', {
                                                time: 1*1000
                                                ,success: function(layero, index){
                                                    var timeNum = this.time/1000, setText = function(start){
                                                        layer.title((start ? timeNum : --timeNum) + ' 秒后关闭', index);
                                                    };
                                                    setText(!0);
                                                    this.timer = setInterval(setText, 1000);
                                                    if(timeNum <= 0) clearInterval(this.timer);
                                                    table.reload('currentTableId', {
                                                        page: {
                                                            curr: 1
                                                        }
                                                        , where: data.field
                                                    }, 'data');
                                                }
                                                ,end: function(){
                                                    clearInterval(this.timer);
                                                    layer.close(index);
                                                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                                                    parent.layer.close(iframeIndex);
                                                    window.parent.reload();
                                                }
                                            });
                                        } else {
                                            layer.open({
                                                title: res.message,
                                                btn: [ '确认' ],
                                                content: (res.message || '退出失败' ),
                                                icon: '2'
                                            });
                                        }

                                    },
                                    error: function (error) {

                                    }
                                })

                            });
                        }
                        else if (res.id === 'stop'){
                            layer.confirm( '确认停止？' , {
                                icon: 3,
                                title: '系统提示' ,
                                btn: [ '确定', '取消' ]
                            }, function(index){
                                layer.close(index);
                                $.ajax({
                                    url: '/job_info/stop',
                                    type: 'POST',
                                    data : {
                                        "id" : data.id
                                    },
                                    dataType : "json",
                                    success: function (res) {
                                        console.log('----------back------ddddddd',res)
                                        if (res.code == "200") {
                                            layer.alert('停止成功', {
                                                time: 1*1000
                                                ,success: function(layero, index){
                                                    var timeNum = this.time/1000, setText = function(start){
                                                        layer.title((start ? timeNum : --timeNum) + ' 秒后关闭', index);
                                                    };
                                                    setText(!0);
                                                    this.timer = setInterval(setText, 1000);
                                                    if(timeNum <= 0) clearInterval(this.timer);
                                                    table.reload('currentTableId', {
                                                        page: {
                                                            curr: 1
                                                        }
                                                        , where: data.field
                                                    }, 'data');
                                                }
                                                ,end: function(){
                                                    clearInterval(this.timer);
                                                    layer.close(index);
                                                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                                                    parent.layer.close(iframeIndex);
                                                    window.parent.reload();
                                                }
                                            });
                                        } else {
                                            layer.open({
                                                title: res.message,
                                                btn: [ '确认' ],
                                                content: (res.message || '退出失败' ),
                                                icon: '2'
                                            });
                                        }

                                    },
                                    error: function (error) {

                                    }
                                })

                            });
                        }
                        else if (res.id === 'nextTime'){
                            $.ajax({
                                url: '/job_info/nextTriggerTime',
                                type: 'POST',
                                data : {
                                    "scheduleType" : data.scheduleType,
                                    "scheduleConf":data.scheduleConf
                                },
                                dataType : "json",
                                success: function (res) {
                                    console.log('----------back------ddddddd',res)
                                    if (res.code == "200") {
                                        var html = '<center>';
                                        if (res.data) {
                                            for (var index in res.data) {
                                                html += '<span>' + res.data[index] + '</span><br>';
                                            }
                                        }
                                        html += '</center>';
                                        layer.open({
                                            title: '下次执行时间' ,
                                            btn: [ '确认'],
                                            content: html
                                        });
                                    } else {
                                        layer.open({
                                            title: res.message,
                                            btn: [ '确认' ],
                                            content: (res.message || '退出失败' ),
                                            icon: '2'
                                        });
                                    }

                                },
                                error: function (error) {

                                }
                            })
                        }
                        else if (res.id === 'registerAddress'){
                            $.ajax({
                                url: '/job_actuator/getById',
                                type: 'POST',
                                data : {
                                    "id" : data.jobActuator
                                },
                                dataType : "json",
                                success: function (res) {
                                    console.log('----------back------ddddddd',res)
                                    if (res.code == "200") {
                                        var html = '<div>';
                                        if (res.code == 200 && res.data.registryList) {
                                            for (var index in res.data.registryList) {
                                                html += (parseInt(index)+1) + '. <span class="badge" style="background: #00a65a !important" >' + res.data.registryList[index] + '</span><br>';
                                            }
                                        }
                                        html += '</div>';

                                        layer.open({
                                            title: '注册节点' ,
                                            btn: '确定',
                                            content: html
                                        });
                                    } else {
                                        layer.open({
                                            title: res.message,
                                            btn: [ '确认' ],
                                            content: (res.message || '失败' ),
                                            icon: '2'
                                        });
                                    }

                                },
                                error: function (error) {

                                }
                            })
                        }
                        else {
                            layer.msg('得到表格下拉菜单 id：'+ res.id);
                        }
                    }
                    ,isAllowSpread:true
                    ,align: 'right' //右对齐弹出（v2.6.8 新增）
                    ,style: 'box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);' //设置额外样式
                });
            }
        });




        form.render();
    });
    //引入模板后调用代码
    $("#schedule_conf_cron").cronGen({
        direction : 'right'
    });


    function reload() {
        location.reload();
    }

    /**
     * find title by name, GlueType
     */
    function findGlueTypeTitle(glueType) {
        return $('select[id="glueType"]').text();
    }
    function cancelOnceTime(){
        var targetModal = document.getElementById('runOnceTimeId');
        closeModal(targetModal);
    }
    function exeOnceTime() {

        var executorParamOnTime  = $('textarea[id="executorParamOnTime"]').val();
        var addressListOnceTime  = $('textarea[id="addressListOnceTime"]').val();
        var req={
            id:this.jobId,
            executorParam:executorParamOnTime,
            addressList:addressListOnceTime
        }
        console.log('--reqreqreqreqreqreq----',req);
        $.ajax({
            url: '/job_info/trigger',
            type: 'post',
            async: false,
            data:JSON.stringify(req),
            contentType: 'application/json;charset=UTF-8',
            success: function (response) {

                if (response.code=="200"){
                    layer.alert('保存成功', {
                        time: 1*1000
                        ,success: function(layero, index){
                            var timeNum = this.time/1000, setText = function(start){
                                layer.title((start ? timeNum : --timeNum) + ' 秒后关闭', index);
                            };
                            setText(!0);
                            this.timer = setInterval(setText, 1000);
                            if(timeNum <= 0) clearInterval(this.timer);
                            setTimeout(function() {
                                cancelOnceTime()// 延时1秒后执行的代码
                            }, 1000);
                        }
                        ,end: function(){
                            clearInterval(this.timer);
                            layer.close(index);
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                            window.parent.reload();
                        }
                    });
                }else if (response.code=="500"){
                    layer.msg(response.message, {
                        offset: 'd',
                        anim: 1
                    });
                    layer.close(index);
                }



            },
            error: function (error) {
                console.log(1234566);
                console.log('error',error)
                layer.alert(error.responseJSON.message)
                layer.close(index);
            }
        })

        console.log('----fbsJobInfo---------',fbsJobInfo)

    }

    function  saveJobInfo(){
        var jobActuator  = $('select[id="jobActuator"]').val();
        var jobDesc  = $('input[id="jobDesc"]').val();
        var author  = $('input[id="author"]').val();
        var alarmEmail  = $('input[id="alarmEmail"]').val();
        var scheduleType  = $('select[id="scheduleType"]').val();
        var scheduleConf = '';
        if (scheduleType=='NONE'){
            scheduleConf = '';
        } else if (scheduleType=='CRON'){
            scheduleConf = $('input[id="schedule_conf_cron"]').val();
        }else if (scheduleType=='FIX_RATE'){
            scheduleConf = $('input[id="schedule_conf_fix_rate"]').val();
        }
        var glueType  = $('select[id="glueType"]').val();
        var executorHandler  = $('input[id="executorHandler"]').val();
        var executorParam  = $('textarea[id="executorParam"]').val();
        var executorRouteStrategy  = $('select[id="executorRouteStrategy"]').val();
        var childJobid  = $('input[id="childJobid"]').val();
        var misfireStrategy  = $('select[id="misfireStrategy"]').val();
        var executorBlockStrategy  = $('select[id="executorBlockStrategy"]').val();
        var executorTimeout  = $('input[id="executorTimeout"]').val();
        var executorFailRetryCount  = $('input[id="executorFailRetryCount"]').val();
        var id  = $('input[id="id"]').val();
        var fbsJobInfo ={
            jobActuator:jobActuator,
            id:id,
            jobDesc:jobDesc,
            author:author,
            alarmEmail:alarmEmail,
            scheduleType:scheduleType,
            scheduleConf:scheduleConf,
            glueType:glueType,
            executorHandler:executorHandler,
            executorParam:executorParam,
            executorRouteStrategy:executorRouteStrategy,
            childJobid:childJobid,
            misfireStrategy:misfireStrategy,
            executorBlockStrategy:executorBlockStrategy,
            executorTimeout:executorTimeout,
            executorFailRetryCount:executorFailRetryCount

        }
        var url = '/job_info/add';
        if (id!=undefined&&id!='') {
            url =  '/job_info/update';
        }
        $.ajax({
            url: url,
            type: 'post',
            async: false,
            data:JSON.stringify(fbsJobInfo),
            contentType: 'application/json;charset=UTF-8',
            success: function (response) {

                if (response.code=="200"){
                    layer.alert('保存成功', {
                        time: 1*1000
                        ,success: function(layero, index){
                            var timeNum = this.time/1000, setText = function(start){
                                layer.title((start ? timeNum : --timeNum) + ' 秒后关闭', index);
                            };
                            setText(!0);
                            this.timer = setInterval(setText, 1000);
                            if(timeNum <= 0) clearInterval(this.timer);
                            location.reload();
                            cancelBtn();

                        }
                        ,end: function(){
                            clearInterval(this.timer);
                            layer.close(index);
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                            window.parent.reload();
                        }
                    });
                }else if (response.code=="500"){
                    layer.msg(response.message, {
                        offset: 'd',
                        anim: 1
                    });
                    layer.close(index);
                }



            },
            error: function (error) {
                console.log(1234566);
                console.log('error',error)
                layer.alert(error.responseJSON.message)
                layer.close(index);
            }
        })

        console.log('----fbsJobInfo---------',fbsJobInfo)
    }
    // 获取触发模态框的自定义属性
    var modalButtons = document.querySelectorAll("[data-modal-action]");

    // 获取模态框主体
    var modals = document.querySelectorAll(".modal");

    function cancelBtn(){
        var targetModal = document.getElementById('myModal');
        closeModal(targetModal);
    }
    // 监听模态框的按钮事件
    modalButtons.forEach(function(button) {
        button.addEventListener("click", function() {
            var targetId = this.dataset.modalTarget;
            var targetModal = document.getElementById(targetId);

            if (targetModal) {
                var action = this.dataset.modalAction;

                if (action === "open") {
                    this.jobId=undefined;
                    $('select[id="jobActuator"]').val(undefined);
                    $('input[id="jobDesc"]').val(undefined);
                    $('input[id="author"]').val(undefined);
                    $('input[id="alarmEmail"]').val(undefined);

                    $("#scheduleType").find("option:selected").text();//选中的文本
                    $("#scheduleType").find("option:selected").val();//选中的值
                    $("#scheduleType").find("option:selected").get(0).selectedIndex;//索引


                    var scheduleConf = '';
                    $('input[id="cronId"]').val(undefined);
                    $('input[id="schedule_conf_fix_rate"]').val(undefined);

                    $("#glueType").find("option:selected").text();//选中的文本
                    $("#glueType").find("option:selected").val();//选中的值
                    $("#glueType").find("option:selected").get(0).selectedIndex;//索引


                    $('input[id="executorHandler"]').val(undefined);
                    $('textarea[id="executorParam"]').val(undefined);
                    $("#executorRouteStrategy").find("option:selected").text();//选中的文本
                    $("#executorRouteStrategy").find("option:selected").val();//选中的值
                    $("#executorRouteStrategy").find("option:selected").get(0).selectedIndex;//索引


                    $('input[id="childJobid"]').val(undefined);
                    $("#misfireStrategy").find("option:selected").text();//选中的文本
                    $("#misfireStrategy").find("option:selected").val();//选中的值
                    $("#misfireStrategy").find("option:selected").get(0).selectedIndex;//索引


                    $("#executorBlockStrategy").find("option:selected").text();//选中的文本
                    $("#executorBlockStrategy").find("option:selected").val();//选中的值
                    $("#executorBlockStrategy").find("option:selected").get(0).selectedIndex;//索引



                    $('input[id="executorTimeout"]').val(undefined);
                    $('input[id="executorFailRetryCount"]').val(undefined);
                    $('input[id="id"]').val(undefined);
                    openModal(targetModal);
                } else if (action === "close") {
                    closeModal(targetModal);
                }
            }
        });
    });

    // 打开模态框
    function openModal(modal) {
        modal.style.display = "block";
        modal.querySelector(".modal-content").classList.remove("modal-hide");
    }
    // 打开模态框
    function openModal2(modal,id) {
        this.jobId=id;
        modal.style.display = "block";
        modal.querySelector(".modal-content").classList.remove("modal-hide");
    }

    function openModalEdit(modal,data,form) {
        this.jobId=data.id;
         $('select[id="jobActuator"]').val(data.jobActuator);
         $('input[id="jobDesc"]').val(data.jobDesc);
         $('input[id="author"]').val(data.author);
         $('input[id="alarmEmail"]').val(data.alarmEmail);

        $('select[id="scheduleType"]').val(data.scheduleType);

        var scheduleConf = '';
        if (data.scheduleType=='NONE'){
        } else if (data.scheduleType=='CRON'){
             $('input[id="cronId"]').val(data.scheduleConf);
             $('input[id="schedule_conf_cron"]').val(data.scheduleConf);
        }else if (data.scheduleType=='FIX_RATE'){
            $('input[id="schedule_conf_fix_rate"]').val(data.scheduleConf);
        }

        if (data.scheduleType=='NONE') {
            document.getElementById('id_none').style.display="block";
            document.getElementById('id_cron').style.display="none";
            document.getElementById('id_fix_rate').style.display="none";
        }else if (data.scheduleType=='CRON') {
            document.getElementById('id_none').style.display="none";
            document.getElementById('id_cron').style.display="block";
            document.getElementById('id_fix_rate').style.display="none";
        }else if (data.scheduleType=='FIX_RATE') {
            document.getElementById('id_none').style.display="none";
            document.getElementById('id_cron').style.display="none";
            document.getElementById('id_fix_rate').style.display="block";
        }
        $('select[id="glueType"]').val(data.glueType);
        $('input[id="executorHandler"]').val(data.executorHandler);
        $('textarea[id="executorParam"]').val(data.executorParam);
        $('select[id="executorRouteStrategy"]').val(data.executorRouteStrategy);
        $('input[id="childJobid"]').val(data.childJobid);
        $('select[id="misfireStrategy"]').val(data.misfireStrategy);
        $('select[id="executorBlockStrategy"]').val(data.executorBlockStrategy);
        $('input[id="executorTimeout"]').val(data.executorTimeout);
        $('input[id="executorFailRetryCount"]').val(data.executorFailRetryCount);
        $('input[id="id"]').val(data.id);

        form.render('select');
        modal.style.display = "block";
        modal.querySelector(".modal-content").classList.remove("modal-hide");
    }


    // 关闭模态框
    function closeModal(modal) {
        modal.querySelector(".modal-content").classList.add("modal-hide");
        modal.querySelector(".modal-content").addEventListener("animationend", function () {
            modal.style.display = "none";
        }, { once: true });
    }

    // 监听模态框的关闭时事件
    modals.forEach(function(modal) {
        var closeButton = modal.querySelector(".close");
        if (closeButton) {
            closeButton.addEventListener("click", function() {
                var targetModal = this.closest(".modal");
                closeModal(targetModal);
            });
        }
    });

    // 当用户点击模态框外部时，关闭模态框
    window.onclick = function (event) {
        modals.forEach(function(modal) {
            if (event.target === modal) {
                closeModal(modal);
            }
        });
    };
</script>
<style>
    /*模态框主体样式*/
    .modal {
        display: none;
        position: fixed;
        z-index: 1;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        overflow: auto;
        background-color: rgba(0, 0, 0, 0.5);
    }

    /*模态框公共样式*/
    .modal-content {
        background-color: #fefefe;
        margin: 50px auto 0;
        padding: 20px;
        border: 1px solid #888;
        box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
        animation: modal-show 0.3s;
    }

    /* 正常大小 */
    .modal-normal {
        width: 1000px;
    }

    /* 中等大小 */
    .modal-medium {
        width: 400px;
    }

    /* 迷你大小 */
    .modal-mini {
        width: 250px;
    }

    /* 隐藏 */
    .modal-hide {
        animation: modal-hide 0.3s;
    }

    /* 展示动画 */
    @keyframes modal-show {
        from {
            opacity: 0;
            transform: translateY(-50px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    /* 隐藏动画 */
    @keyframes modal-hide {
        from {
            opacity: 1;
            transform: translateY(0);
        }
        to {
            opacity: 0;
            transform: translateY(-50px);
        }
    }

    /*关闭按钮*/
    .close {
        color: #aaa;
        float: right;
        font-size: 28px;
        font-weight: bold;
        cursor: pointer;
        margin-bottom: 12px;
        -webkit-tap-highlight-color: rgba(255,0,0,0);
    }

    /*关闭按钮的鼠标点击和经过样式*/
    .close:hover,
    .close:focus {
        color: black;
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(255,0,0,0);
    }
</style>
</body>
</html>